root.customUploader = {};
root.customUploader.uploadImage = {
    init: function (resultContainer, uploadContainer,ctx) {
    	if(ctx===undefined){
    		ctx="";
    	}
        $("#"+uploadContainer).html('<div id="thelist" style="display: none"></div><div id="picker">选择文件</div><span id="upload-msg"></span>');
        var $uploadMsg = $("#upload-msg"),
            uploader = WebUploader.create({
                swf: ctx+"/static/assets/webuploader/Uploader.swf",
                server: ctx+"/tools/doUpload.jspx?t=images&format=json",
                pick: "#picker",
                resize: true,
                auto: true,
                accept: {
                    title: 'Images',
                    extensions: 'gif,jpg,jpeg,bmp,png',
                    mimeTypes: 'image/*'
                }
            });
        // 当有文件被添加进队列的时候
        uploader.on('fileQueued', function (file) {
            $uploadMsg.append('<span id="' + file.id + '" class="item">' +
                '<span class="info">' + file.name + '</span>' +
                '<span class="state">等待上传...</span>' +
                '</span>');
        });
        uploader.on('uploadSuccess', function (file, data) {
            $("#" + resultContainer).val(data.filestatus.url);
            $('#' + file.id).find('span.state').text('已上传');
        });

        uploader.on('uploadError', function (file) {
            $('#' + file.id).find('span.state').text('上传出错');
        });
    }, destory: function (uploadContainer) {
        $("#"+uploadContainer).html('');
    }
};

root.customUploader.uploadFiles = {
    init: function (resultContainer, uploadContainer,ctx) {
    	if(ctx===undefined){
    		ctx="";
    	}
        $("#"+uploadContainer).html('<div id="thelist" style="display: none"></div><div id="picker">选择文件</div><span id="upload-msg"></span>');
        var $uploadMsg = $("#upload-msg"),
            uploader = WebUploader.create({
                swf: ctx+"/static/assets/webuploader/Uploader.swf",
                server: ctx+"/tools/doUpload.jspx?t=files&format=json",
                pick: "#picker",
                resize: true,
                auto: true
            });
        // 当有文件被添加进队列的时候
        uploader.on('fileQueued', function (file) {
            $uploadMsg.append('<span id="' + file.id + '" class="item">' +
                '<span class="info">' + file.name + '</span>' +
                '<span class="state">等待上传...</span>' +
                '</span>');
        });
        uploader.on('uploadSuccess', function (file, data) {
            $("#" + resultContainer).val(data.filestatus.url);
            $('#' + file.id).find('span.state').text('已上传');
        });

        uploader.on('uploadError', function (file) {
            $('#' + file.id).find('span.state').text('上传出错');
        });
    }, destory: function (uploadContainer) {
        $("#"+uploadContainer).html('');
    }
};
